/**
 * @file
 * @author jinguangguo
 * @date 2017/10/12
 */

import Vue from 'vue';
import moment from 'moment';
import lib from './lib';
import mathtool from '../../grsc-base/util/mathtool';
import {PAY_TYPE_ALIPAY, PAY_TYPE_BANK} from './contants';

let currentTimezone = lib.getCurrentTimezone();

Vue.filter('timezone', function(value, format = 'YYYY-MM-DD HH:mm:ss') {
    return moment(value).utc().utcOffset(-currentTimezone).format(format);
});

Vue.filter('timezoneUnix', function(value, format = 'YYYY-MM-DD HH:mm:ss') {
    return moment.unix(value).utc().utcOffset(-currentTimezone).format(format);
});

Vue.filter('ratio', function(value) {
    if ($.isNumeric(value) === false) {
        return value;
    }
    return mathtool.multiplication(value, 100);
});

Vue.filter('payTypesFilter', function(value) {
    if (value === PAY_TYPE_ALIPAY) {
        return '支付宝';
    } else if (value === PAY_TYPE_BANK) {
        return '银行卡';
    }
});
Vue.filter('countryFilter', function(value) {
    if (value === '香港') {
        return '香港(中国)';
    } else {
        return value;
    }
});
